package senior.ListExer.Exer3;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author shkstart
 * @creat 2022-04-10:52
 */
public class SetTest {
    public static void main(String[] args) {
        Set set = new HashSet();
        set.add("mom");
        set.add("dad");
        set.add("son");
        set.add("dog");
        set.add("cat");
        System.out.println("---数组迭代---");
        Object[] array = set.toArray();
        for(int i = 0;i < array.length;i++){
            System.out.print(array[i] + "\t");
        }
        System.out.println();
        System.out.println("---增强for迭代---");
        for(Object o:set){
            System.out.print(o + "\t");
        }
        System.out.println();
        System.out.println("---迭代器迭代---");
        Iterator it = set.iterator();
        while (it.hasNext()){
            System.out.print(it.next() + "\t");
        }
        System.out.println();

    }
}
